/*
 * com_cute4j_swing_SwingGraphics.cpp  0.4.0 / 2010-12-23
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "com_cute4j_swing_SwingGraphics.h"

#include "ComponentDelegate.h"
#include "SwingGraphics.h"
#include "SwingImageDelegate.h"

/*
 * Native implementation for: com.cute4j.swing.SwingGraphics
 */

JNIEXPORT jobject JNICALL
Java_com_cute4j_swing_SwingGraphics__1getColor
  (JNIEnv *env, jobject, jlong graphicsPointer)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    return swingGraphics->getColor();
  }
  return 0;
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1setColor
  (JNIEnv *env, jobject, jlong graphicsPointer, jint argb)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->setColor(argb);
  }
}

JNIEXPORT jobject JNICALL
Java_com_cute4j_swing_SwingGraphics__1getFont
  (JNIEnv *env, jobject, jlong graphicsPointer)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    return swingGraphics->getFont();
  }
  return 0;
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1setFont
  (JNIEnv *env, jobject, jlong graphicsPointer, jobject font)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->setFont(font);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1setLinearGradient
  (JNIEnv *env, jobject, jlong graphicsPointer, jint x1, jint y1, jint argb1,
   jint x2, jint y2, jint argb2, jboolean cyclic)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->setLinearGradient(x1, y1, argb1, x2, y2, argb2, cyclic);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1setTextureGradient
  (JNIEnv *env, jobject, jlong graphicsPointer, jlong imagePointer)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->setTextureGradient(SWING_IMAGE);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1setBasicStroke
  (JNIEnv *env, jobject, jlong graphicsPointer, jfloat width, jint cap,
   jint join, jfloat miterLimit, jfloatArray dash, jfloat dashPhase)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->setBasicStroke(width, cap, join, miterLimit, dash,
                                  dashPhase);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawPath
  (JNIEnv *env, jobject, jlong graphicsPointer, jlong painterPathPointer)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawPath(*qPainterPath);
    delete qPainterPath;
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawLine
  (JNIEnv *env, jobject, jlong graphicsPointer, jint x1, jint y1, jint x2,
   jint y2)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawLine(x1, y1, x2, y2);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawRect
  (JNIEnv *env, jobject, jlong graphicsPointer, jint x, jint y, jint width,
   jint height)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawRect(x, y, width, height);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawOval
  (JNIEnv *env, jobject, jlong graphicsPointer, jint x, jint y, jint width,
   jint height)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawEllipse(x, y, width, height);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawString
  (JNIEnv *env, jobject, jlong graphicsPointer, jstring str, jint x, jint y)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawText(x, y, QStringAdapter(env, str));
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawImage__JJII
  (JNIEnv *env, jobject, jlong graphicsPointer, jlong imagePointer, jint x,
   jint y)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawPixmap(x, y, *SWING_IMAGE);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1drawImage__J_3BIII
  (JNIEnv *env, jobject, jlong graphicsPointer, jbyteArray imageData,
   jint length, jint x, jint y)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->drawImage(imageData, length, x, y);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1fillPath
  (JNIEnv *env, jobject, jlong graphicsPointer, jlong painterPathPointer)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->fillPath(*qPainterPath, swingGraphics->pen().brush());
    delete qPainterPath;
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1fillRect
  (JNIEnv *env, jobject, jlong graphicsPointer, jint x, jint y, jint width,
   jint height)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->fillRect(x, y, width, height);
  }
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1fillOval
  (JNIEnv *env, jobject, jlong graphicsPointer, jint x, jint y, jint width,
   jint height)
{
  if (SwingGraphics::canPaint(env, graphicsPointer)) {
    swingGraphics->fillOval(x, y, width, height);
  }
}

JNIEXPORT jlong JNICALL
Java_com_cute4j_swing_SwingGraphics__1createPainterPath
  (JNIEnv *, jclass)
{
  return reinterpret_cast<jlong>(new QPainterPath());
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1setPainterFillRule
  (JNIEnv *, jclass, jlong painterPathPointer, jint fillRule)
{
  qPainterPath->setFillRule(Qt::FillRule(fillRule)); // painterPathPointer != 0
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1painterPathMoveTo
  (JNIEnv *, jclass, jlong painterPathPointer, jint x, jint y)
{
  qPainterPath->moveTo(x, y); // painterPathPointer != 0
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1painterPathLineTo
  (JNIEnv *, jclass, jlong painterPathPointer, jint x, jint y)
{
  qPainterPath->lineTo(x, y); // painterPathPointer != 0
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1painterPathQuadTo
  (JNIEnv *, jclass, jlong painterPathPointer, jint cx, jint cy, jint ex,
   jint ey)
{
  qPainterPath->quadTo(cx, cy, ex, ey); // painterPathPointer != 0
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1painterPathCubicTo
  (JNIEnv *, jclass, jlong painterPathPointer, jint c1x, jint c1y,
   jint c2x, jint c2y, jint ex, jint ey)
{
  qPainterPath->cubicTo(c1x, c1y, c2x, c2y, ex, ey); // painterPathPointer != 0
}

JNIEXPORT void JNICALL
Java_com_cute4j_swing_SwingGraphics__1painterPathClose
  (JNIEnv *, jclass, jlong painterPathPointer)
{
  qPainterPath->closeSubpath(); // painterPathPointer != 0
}


